﻿//
// *************************************************************************************
// WP-Framework
// 
// Developed by
// Lukas Kretschmar (lkretschmar.dev@bluewin.ch)
//
// Switzerland, Copyright (c) 2013 lkretschmar
// This content is released under the MIT License (http://opensource.org/licenses/MIT).
//     
// *************************************************************************************
//
//



using Microsoft.VisualStudio.TestTools.UnitTesting;
using KretschIT.WP_Fx.EasyMoq.Generator.Usings;
using System.Linq;
using KretschIT.WP_Fx.EasyMoq.Generator.Tests.Helpers.Objects;
using System;
using System.Collections.Generic;
using KretschIT.WP_Fx.EasyMoq.Generator.Tests.Helpers.Objects.Custom;

namespace KretschIT.WP_Fx.EasyMoq.Generator.Tests.Usings
{
    [TestClass]
    public class UsingsBuilderTest
    {
        private IUsingsBuilder usings;

        [TestInitialize]
        public void Init()
        {
            this.usings = new UsingsBuilder();
        }

        [TestMethod]
        public void Test_InitValues()
        {
            Assert.IsNotNull(this.usings.Usings);
            Assert.AreEqual(0, this.usings.Usings.Count());
        }

        [TestMethod]
        public void Test_Add()
        {
            this.usings.Add(typeof(ITestObject));
            Assert.AreEqual(1, this.usings.Usings.Count());
        }

        [TestMethod]
        public void Test_Add_SameUsing()
        {
            this.usings.Add(typeof(ITestObject));
            this.usings.Add(typeof(ITestObject));
            Assert.AreEqual(1, this.usings.Usings.Count());
        }

        [TestMethod]
        public void Test_Add_SameUsing_OtherTypes()
        {
            this.usings.Add(typeof(ITestObject));
            this.usings.Add(typeof(ITestOtherObject));
            Assert.AreEqual(1, this.usings.Usings.Count());
        }

        [TestMethod]
        public void Test_AddMany()
        {
            List<Type> types = new List<Type>
            {
                typeof(ITestObject),
                typeof(ITestOtherObject),
                typeof(IOtherNamespaceObject)
            };
            this.usings.Add(types);
            Assert.AreEqual(2, this.usings.Usings.Count());
        }

        [TestMethod]
        public void Test_Add_NullArgument()
        {
            this.usings.Add((Type)null);
            Assert.AreEqual(0, this.usings.Usings.Count());
        }

        [TestMethod]
        public void Test_AddMany_NullArgument()
        {
            this.usings.Add((IEnumerable<Type>)null);
            Assert.AreEqual(0, this.usings.Usings.Count());
        }

        [TestMethod]
        public void Test_Merge()
        {
            IUsingsBuilder otherUsings = new UsingsBuilder();
            otherUsings.Add(typeof(ITestObject));
            this.usings.Merge(otherUsings);
            Assert.AreEqual(1, this.usings.Usings.Count());
        }

        [TestMethod]
        public void Test_Merge_SameNamespaces()
        {
            IUsingsBuilder otherUsings = new UsingsBuilder();
            otherUsings.Add(typeof(ITestObject));
            this.usings.Add(typeof(ITestObject));
            this.usings.Merge(otherUsings);
            Assert.AreEqual(1, this.usings.Usings.Count());
        }

        [TestMethod]
        public void Test_Merge_DifferentNamespaces()
        {
            IUsingsBuilder otherUsings = new UsingsBuilder();
            otherUsings.Add(typeof(IOtherNamespaceObject));
            this.usings.Add(typeof(ITestObject));
            this.usings.Merge(otherUsings);
            Assert.AreEqual(2, this.usings.Usings.Count());
        }

        [TestMethod]
        public void Test_Merge_NullArgument()
        {
            this.usings.Merge(null);
            Assert.AreEqual(0, this.usings.Usings.Count());
        }

        [TestMethod]
        public void Test_AddManyStrings()
        {
            List<string> strings = new List<string>
            {
                "Test",
                "Asdf",
            };
            this.usings.Add(strings);
            Assert.AreEqual(2, this.usings.Usings.Count());
        }

        [TestMethod]
        public void Test_AddManyStrings_Same()
        {
            List<string> strings = new List<string>
            {
                "Test",
                "Test",
            };
            this.usings.Add(strings);
            Assert.AreEqual(1, this.usings.Usings.Count());
        }

        [TestMethod]
        public void Test_AddManyStrings_NullArgument()
        {
            this.usings.Add((IEnumerable<string>)null);
            Assert.AreEqual(0, this.usings.Usings.Count());
        }

        [TestMethod]
        public void Test_Remove_NullArgument()
        {
            this.usings.Add(typeof(ITestObject));
            this.usings.Remove(null);
            Assert.AreEqual(1, this.usings.Usings.Count());
        }

        [TestMethod]
        public void Test_Remove()
        {
            this.usings.Add(typeof(ITestObject));
            this.usings.Add(typeof(IOtherNamespaceObject));
            var remover = new UsingsBuilder();
            remover.Add(typeof(ITestObject));
            this.usings.Remove(remover);
            Assert.AreEqual(1, this.usings.Usings.Count());
        }
    }
}
